package com.googlecode.perfectable.visuable.event;

import java.util.LinkedList;
import java.util.List;

public final class CompositeEventListener<E extends Event> implements EventListener<E> {

	private List<EventListener<E>> listeners = new LinkedList<>();

	private CompositeEventListener() {
	}

	public static <X extends Event> CompositeEventListener<X> create() {
		return new CompositeEventListener<>();
	}

	@Override
	public void receive(E event) {
		for(EventListener<E> listener : this.listeners) {
			listener.receive(event);
		}
	}

	public void add(EventListener<E> listener) {
		this.listeners.add(listener);
	}

}
